﻿// -----------------------------------------------------------------------
// <copyright file="ConfigurationFileSettings.cs" company="Microsoft">
//  LoLz
// </copyright>
// -----------------------------------------------------------------------

namespace Eeeek
{
    using System.Globalization;
    using System.IO;

    using Eeeek.Configuration;

    /// <summary>
    /// Pulls properly typed data from the config file.
    /// </summary>
    public class ConfigurationFileSettings
    {
        /// <summary>
        /// The configuration file manager
        /// </summary>
        private readonly ConfigurationFileManager configurationFileManager;

        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigurationFileSettings"/> class.
        /// </summary>
        /// <param name="configurationFile">The configuration file.</param>
        public ConfigurationFileSettings(string configurationFile)
        {
            this.configurationFileManager = new ConfigurationFileManager(configurationFile);
        }

        /// <summary>
        /// Gets or sets the pre-batch start delay.
        /// </summary>
        /// <value>
        /// The pre-batch start delay.
        /// </value>
        public int PrebatchStartDelayInSeconds
        {
            get
            {
                return this.configurationFileManager.GetValue<int>("PrebatchStartDelayInSeconds");
            }

            set
            {
                this.configurationFileManager.SetValue("PrebatchStartDelayInSeconds", value.ToString(CultureInfo.CurrentUICulture));
            }
        }

        /// <summary>
        /// Gets or sets the target window title.
        /// </summary>
        /// <value>
        /// The target window title.
        /// </value>
        public string TargetWindowTitle
        {
            get
            {
                return this.configurationFileManager.GetValue<string>("TargetWindowTitle");
            }

            set
            {
                this.configurationFileManager.SetValue("TargetWindowTitle", value.ToString(CultureInfo.InvariantCulture));
            }
        }

        /// <summary>
        /// Gets or sets the number of previous sessions in the menu.
        /// </summary>
        /// <value>
        /// The number of previous sessions in the menu.
        /// </value>
        public int NumberOfPreviousSessionsInTheMenu
        {
            get
            {
                return this.configurationFileManager.GetValue<int>("NumberOfPreviousSessionsInTheMenu");
            }

            set
            {
                this.configurationFileManager.SetValue("NumberOfPreviousSessionsInTheMenu", value.ToString(CultureInfo.InvariantCulture));
            }
        }

        /// <summary>
        /// Gets or sets the default delay between clicks in milliseconds.
        /// </summary>
        /// <value>
        /// The default delay between clicks in milliseconds.
        /// </value>
        public int DefaultDelayBetweenClicksInMilliseconds
        {
            get
            {
                return this.configurationFileManager.GetValue<int>("DefaultDelayBetweenClicksInMilliseconds");
            }

            set
            {
                this.configurationFileManager.SetValue("DefaultDelayBetweenClicksInMilliseconds", value.ToString(CultureInfo.InvariantCulture));
            }
        }

        /// <summary>
        /// Gets or sets the default delay between iterations in seconds.
        /// </summary>
        /// <value>
        /// The default delay between iterations in seconds.
        /// </value>
        public int DefaultDelayBetweenIterationsInSeconds
        {
            get
            {
                return this.configurationFileManager.GetValue<int>("DefaultDelayBetweenIterationsInSeconds");
            }

            set
            {
                this.configurationFileManager.SetValue("DefaultDelayBetweenIterationsInSeconds", value.ToString(CultureInfo.InvariantCulture));
            }
        }

        /// <summary>
        /// Gets or sets the default number of repetitions.
        /// </summary>
        /// <value>
        /// The default number of repetitions.
        /// </value>
        public int DefaultNumberOfRepetitions
        {
            get
            {
                return this.configurationFileManager.GetValue<int>("DefaultNumberOfRepetitions");
            }

            set
            {
                this.configurationFileManager.SetValue("DefaultNumberOfRepetitions", value.ToString(CultureInfo.InvariantCulture));
            }
        }

        /// <summary>
        /// Gets or sets the mouse button up down delay in milliseconds.
        /// </summary>
        /// <value>
        /// The mouse button up down delay in milliseconds.
        /// </value>
        public int MouseButtonUpDownDelayInMilliseconds
        {
            get
            {
                return this.configurationFileManager.GetValue<int>("MouseButtonUpDownDelayInMilliseconds");
            }

            set
            {
                this.configurationFileManager.SetValue("MouseButtonUpDownDelayInMilliseconds", value.ToString(CultureInfo.InvariantCulture));
            }
        }

        /// <summary>
        /// Gets or sets the log file.
        /// </summary>
        /// <value>
        /// The log file.
        /// </value>
        public FileInfo LogFile
        {
            get
            {
                var result = this.configurationFileManager.GetValue<string>("LogFile");

                if (!string.IsNullOrWhiteSpace(result))
                {
                    return new FileInfo(result);
                }

                return null;
            }

            set
            {
                this.configurationFileManager.SetValue("LogFile", value.FullName);
            }
        }
    }
}
